<?php
class MenuAction extends Action{
	/**
	 * To get the menu
	 */
	public function _initialize(){
		$Category = M('Category');
		$Channel = M('Channel');
		$Link = M('Link');
		$mainnavi = $Category->where('category_state=1')->order('category_sort asc')->select();
		$Channel = M('Channel');
		$subnavi = $Channel->where('channel_state=1')->select();
		$Page = M("Page");
		$pagefront = $Page->where('page_front=1')->order('page_navisort asc')->select();
		$pageback = $Page->where('page_front=0')->order('page_navisort asc')->select();
		$count[] = count($pagefront);
		$count[] = count($mainnavi);
		$imagelink = $Link->where('link_logo != ""')->order('link_sort asc')->select();
		$txtlink = $Link->where('link_logo = ""')->order('link_sort asc')->select();
		$this->assign('imagelink',$imagelink);
		$this->assign('txtlink',$txtlink);
		$this->assign('count',$count);
		$this->assign('pagefront',$pagefront);
		$this->assign('pageback',$pageback);
		$this->assign('subnavi',$subnavi);
		$this->assign('main',$mainnavi);
	}
        
        /**
     +----------------------------------------------------------
     * Ajax方式返回数据到客户端
     +----------------------------------------------------------
     * @access protected
     +----------------------------------------------------------
     * @param mixed $data 要返回的数据
     * @param String $info 提示信息
     * @param boolean $status 返回状态
     * @param String $status ajax返回类型 JSON XML
     +----------------------------------------------------------
     * @return void
     +----------------------------------------------------------
     */
    protected function ajaxReturn($data,$info='',$status=1,$type='')
    {
        // 保证AJAX返回后也能保存日志
        if(C('LOG_RECORD')) Log::save();
        $result  =  array();
        $result['status']  =  $status;
        $result['info'] =  $info;
        $result['data'] = $data;
        if(empty($type)) $type  =   C('DEFAULT_AJAX_RETURN');
        if(strtoupper($type)=='JSON') {
            // 返回JSON数据格式到客户端 包含状态信息
            header("Content-Type:application/json; charset=utf-8");
            exit(json_encode($result));
        }elseif(strtoupper($type)=='XML'){
            // 返回xml格式数据
            header("Content-Type:text/xml; charset=utf-8");
            exit(xml_encode($result));
        }elseif(strtoupper($type)=='EVAL'){
            // 返回可执行的js脚本
            header("Content-Type:text/html; charset=utf-8");
            exit($data);
        }else{
            // TODO 增加其它格式
        }
    }
}
?>
